﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ObserverPatternWithDelegate
{
    public class EventListener
    {
        public ListWithChangedEvent List;

        public EventListener(ListWithChangedEvent list) 
        {
            this.List = list;
            List.Changed += new ChangedEventHandler(ListChanged);
        }

        private void ListChanged(object sender, EventArgs e) 
        {
            Console.WriteLine("This is caller when event fires {0}",sender);
        }

        public void Deatch() 
        {
            List.Changed -= new ChangedEventHandler(ListChanged);
            List = null;
        }
    }
}
